<template>
  <div>
    <Layout title="考勤审核">
      <div class="content">
        <van-tabs v-model:active="active" sticky offset-top="40px">
          <van-tab title="待我审批">
            <div
              class="box"
              v-for="i in list.pendinglist"
              :key="i.id"
              :class="list.border[0]"
            >
              <van-cell-group :border="true">
                <van-cell
                  :title="i.username"
                  :value="list.value[0]"
                  label="请假-病假"
                  label-class="label"
                  :value-class="list.color[0]"
                />
                <van-cell center value="2018年4月3日至4月5日，申请时长5天" />
              </van-cell-group>
              <div class="bottom">
                <span @click="passEvt(i)">通过</span>
                <span @click="nopassEvt(i)">驳回</span>
              </div>
            </div>
          </van-tab>
          <van-tab title="我已审批'">
            <div
              class="box"
              v-for="i in list.donelist"
              :key="i.id"
              :class="list.border[i.status]"
            >
              <van-cell-group :border="true">
                <van-cell
                  :title="i.username"
                  :value="list.value[i.status]"
                  label="请假-病假"
                  label-class="label"
                  :value-class="list.color[i.status]"
                />
                <van-cell center value="2018年4月3日至4月5日，申请时长5天" />
              </van-cell-group>
            </div>
          </van-tab>
        </van-tabs>
      </div>
    </Layout>
  </div>
</template>
<script setup>
    import { onMounted, reactive, ref } from 'vue';
    import Layout from '../../common/layout.vue';
    import Navbar from '../components/navbar/index.vue'
    import { checkApi } from '../../apis/approvolApi'
    const active = ref(0)

    onMounted(async function(){
    //    let result =  await checkApi()
    //    console.log(result)
        let result =[
            {id: 1, username: '彭敏', status: 0, startTime: '1994-03-05', endTime: '2019-04-16'},
            {id: 2, username: '杨明', status: 2, startTime: '2009-07-14', endTime: '1980-07-30'},
            {id: 3, username: '丁平', status: 3, startTime: '1971-03-20', endTime: '1987-09-10'},
            {id: 4, username: '孔艳', status: 1, startTime: '2018-05-23', endTime: '2017-09-23'},
            {id: 5, username: '彭秀英', status: 1, startTime: '2006-09-12', endTime: '2015-09-19'},
            {id: 6, username: '沈军', status: 1, startTime: '1988-10-03', endTime: '2021-04-19'},
            {id: 7, username: '毛杰', status: 2, startTime: '1999-08-22', endTime: '2007-10-03'} ,
            {id: 8, username: '袁丽', status: 1, startTime: '1982-01-21', endTime: '2008-12-14'} ,
            {id: 9, username: '龙明', status: 0, startTime: '2005-09-27', endTime: '1976-03-11'}, 
            {id: 10, username: '李磊', status: 0, startTime: '1997-04-02', endTime: '2018-01-20'}, 
            {id: 11, username: '于勇', status: 0, startTime: '1982-04-10', endTime: '2008-04-18'},
            {id: 12, username: '吕强', status: 0, startTime: '1984-08-17', endTime: '2008-01-07'},
            {id: 13, username: '钱敏', status: 2, startTime: '1989-12-11', endTime: '2015-05-04'},
            {id: 14, username: '唐明', status: 3, startTime: '1991-07-02', endTime: '2003-12-16'},
            {id: 15, username: '曹敏', status: 2, startTime: '1990-12-08', endTime: '1979-05-16'}, 
            {id: 16, username: '秦敏', status: 1, startTime: '1982-08-21', endTime: '1973-01-03'},
            {id: 17, username: '田秀兰', status: 3, startTime: '1979-07-26', endTime: '1993-12-14'},
            {id: 18, username: '武超', status: 2, startTime: '1976-01-24', endTime: '2005-10-28'},
            {id: 19, username: '李明', status: 3, startTime: '2016-09-27', endTime: '2002-02-03'},
            {id: 20, username: '宋军', status: 2, startTime: '2000-12-25', endTime: '1991-10-24'}
        ]
       //status表示状态码，0未处理，1表示通过，2表示驳回，3作废
       result.forEach(item => {
         if(item.status>0){
            list.donelist.push(item)
        }else{
            list.pendinglist.push(item)
        }
        
       });
    })
    const list =reactive({
        pendinglist :[],
        donelist:[],
        value:['审批中','已通过','已驳回','已作废'],
        color:['blue_col','green_col','red_col',''],
        border:['blue_border','green_border','red_border','']
    })
    function passEvt(i){
        list.pendinglist=list.pendinglist.filter(item=>item.id!==i.id)
        i.status=1
        list.donelist.unshift(i)
    }
    function nopassEvt(i){
        list.pendinglist=list.pendinglist.filter(item=>item.id!==i.id)
        i.status=2
        list.donelist.unshift(i)
    }

</script>
<style lang="less" scoped>
.box {
  width: 350px;
  margin: 0 auto;
  margin-bottom: 20px;
  border-radius: 8px;
  border-left: 8px solid rgb(92, 90, 90);
}
.bottom {
  background-color: white;
  display: flex;
  justify-content: flex-end;
  align-items: center;
  height: 40px;
  line-height: 40px;
  span {
    display: block;
    font-size: 14px;
    line-height: 30px;
    margin-right: 20px;
    text-align: center;
    width: 50px;
    height: 30px;
    color: #646566;
    border: 1px solid #ccc;
    border-radius: 5px;
  }
}
.red_border {
  border-left: 8px solid rgb(245, 111, 111) !important;
}
.blue_border {
  border-left: 8px solid rgb(30, 128, 219) !important;
}
.green_border {
  border-left: 8px solid rgb(141, 216, 55) !important;
}
</style>
<style lang="less">
.red_col {
  color: rgb(245, 111, 111) !important;
}
.blue_col {
  color: rgb(30, 128, 219) !important;
}
.green_col {
  color: rgb(141, 216, 55) !important;
}
</style>